%% Author: John
%% Created: 2010-6-28
%% Description: TODO: Add description to test_server
-module(test_server).

%%
%% Include files
%%

%%
%% Exported Functions
%%
-export([error_test_server/0, error_test/0]).

%%
%% API Functions
%%

%%
%% TODO: Add description of error_test_server/function_arity
%%
error_test_server() -> 
	{ok,Listen} = gen_tcp:listen(4321,[binary,{packet,2}]),
    {ok,Socket} = gen_tcp:accept(Listen),
    error_test_server_loop(Socket).

%%
%% TODO: Add description of error_test/function_arity
%%
error_test() -> 
	spawn(fun() -> error_test_server() end),
    lib_misc:sleep(2000),
    {ok,Socket} = gen_tcp:connect("localhost",4321,[binary,{packet,2}]),
    io:format("connected to: ~p~n",[Socket]),
    gen_tcp:send(Socket,<<"123">>),
    receive
        Any ->
            io:format("Any=~p~n",[Any])
    end.



%%
%% Local Functions
%%
error_test_server_loop(Socket) ->
    receive
        {tcp,Socket,Data} ->
            io:format("received:~p~n",[Data]),
            atom_to_list(Data),
            error_test_server_loop(Socket)
    end.
